package com.electronsys.dept.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.electronsys.dept.service.IDeptService;
import com.electronsys.pojo.Department;
import com.electronsys.pojo.Employee;
import com.electronsys.pojo.Log;
import com.electronsys.pojo.Module;
import com.electronsys.pojo.ModuleContent;
import com.opensymphony.xwork2.ActionSupport;

public class DeptListAction extends ActionSupport {
	private IDeptService deptService;
	private List<Department> dlist;
	private Integer page = 1;
	private Integer totalPages;
	private static final Integer max = 5;
	private Log log;
	
	public String execute() {
		System.out.println("deptlist....");
		//dlist = deptService.deptList();
		dlist = deptService.deptList();
		int count = dlist.size();
		
		totalPages = ((count % max) == 0)?(count / max):(count / max + 1);
		
		if(page < 1){
			page = 1;
		}
		if(page > totalPages){
			page = totalPages;
		}
		int start = (page - 1) * max ;
		
		dlist = deptService.deptListByPage(start, max);
		
		Module mod = new Module();
		mod.setModId(3001);
		ModuleContent moc = new ModuleContent();
		moc.setMcId(4004);
		Employee emp = new Employee();
		emp.setEmpId(1001);
		
		Date date = new Date();
		
		log = new Log();
		log.setEmployee(emp);
		log.setModule(mod);
		log.setModuleContent(moc);
		log.setLogDate(date);
		
		deptService.addDeptLog(log);
		
		return SUCCESS;
	}

	public List<Department> getDlist() {
		return dlist;
	}

	public void setDlist(List<Department> dlist) {
		this.dlist = dlist;
	}

	public IDeptService getDeptService() {
		return deptService;
	}

	public void setDeptService(IDeptService deptService) {
		this.deptService = deptService;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(Integer totalPages) {
		this.totalPages = totalPages;
	}

	public static Integer getMax() {
		return max;
	}
	
	
	
}
